using Identity.Application.Contracts.Common;
using Identity.Application.Contracts.Services;
using Identity.Application.Roles.Commands;
using MediatR;

namespace Identity.Application.Roles.CommandHandlers
{
    public class GetAllRoleCommandHandler : IRequestHandler<GetAllRoleCommand,Result>
    {
        private readonly IRoleService _roleService;

        public GetAllRoleCommandHandler(IRoleService roleService)
        {
            _roleService = roleService;
        }
        public async Task<Result> Handle(GetAllRoleCommand request, CancellationToken cancellationToken)
        {
            var roles = await _roleService.GetAllRolesAsync();

            if (roles == null) return Result.Failure("获取失败");

            return Result.Success(roles);

        }
    }
}